//
//  EditFoodInfoVC.m
//  dyseller
//
//  Created by 红喇叭 on 2017/11/24.
//  Copyright © 2017年 红喇叭. All rights reserved.
//

#import "EditFoodInfoVC.h"
#import "CategoryListModel.h"
#import "EditAttributeVC.h"
#import "PreviewImageVC.h"
#import "LeftScrollView.h"

#define BottomViewHeight 60     //底部视图的高度
@interface EditFoodInfoVC()<UITableViewDelegate,UITableViewDataSource,UITextFieldDelegate,
LeftScrollViewdelegate>{
    BOOL isInventory;
    NSArray *_titleArray;
    UIImage *_shopImg;
    NSMutableDictionary *_dataDictionary;
    LeftScrollView *_leftScrollView;
    NSMutableDictionary *_recordData;
}

@property(nonatomic,strong)UITableView *defineShopTableView;
@property(nonatomic,copy)NSArray *selectPropertyData;

@end

@implementation EditFoodInfoVC

- (instancetype)init{
    self = [super init];
    if(self){
        [userDefaults removeObjectForKey:HLBPropertyListArray];
    }
    return self;
}


- (void)dealloc{
    [[NSNotificationCenter defaultCenter] removeObserver:self];
}

- (void)viewDidLoad {
    [super viewDidLoad];
    [self setNavTitle:@"自定义商品编辑" titleColor:[UIColor blackColor] font:font17];
    _selectPropertyData = [[NSArray alloc] init];
    [self.view addSubview:self.defineShopTableView];
    self.defineShopTableView.tableHeaderView = [[UIView alloc] initWithFrame:CGRectMake(0, 0, SCREEN_W, 0.1)];
    
    [self addBottomView];
    
    _titleArray = @[@"商品名称",@"商品分类",@"上传图片",@"价格",@"库存无限",@"库存数量"];
    
    [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(updateImage) name:FoodimageUpdate object:nil];
    
    [self getGoodsInfo:_goodsID];
    
    __weak typeof (self)weakself = self;
    [self.backBtn handleControlEvent:UIControlEventTouchUpInside withBlock:^(id sender) {
        if(![self dataContrast]){
            [weakself backAction];
        }else{
            
            [weakself.navigationController popViewControllerAnimated:YES];
        }
    }];
    
    
}

//比较数据源是否被改过
- (BOOL)dataContrast{
    NSData *jsonData = [NSJSONSerialization dataWithJSONObject:_dataDictionary options:NSJSONWritingPrettyPrinted error:nil];
    NSString *jsonStr = [[NSString alloc] initWithData:jsonData encoding:NSUTF8StringEncoding];
    NSString *str1 = [ToolClass md5:jsonStr];
    
    NSData *jsonData1 = [NSJSONSerialization dataWithJSONObject:_recordData options:NSJSONWritingPrettyPrinted error:nil];
    NSString *jsonStr1 = [[NSString alloc] initWithData:jsonData1 encoding:NSUTF8StringEncoding];
    NSString *ptr1 = [ToolClass md5:jsonStr1];
    
    return [str1 isEqualToString:ptr1];
}


- (void)backAction{
    UIAlertController *alertController = [UIAlertController alertControllerWithTitle:@"温馨提示" message:@"是否保存修改的信息" preferredStyle:UIAlertControllerStyleAlert];
    __weak typeof (self)weakSelf = self;
    [alertController addAction:[UIAlertAction actionWithTitle:@"保存" style:UIAlertActionStyleDefault handler:^(UIAlertAction * _Nonnull action) {
        [weakSelf saveAndBack:_dataDictionary];
    }]];
    [alertController addAction:[UIAlertAction actionWithTitle:@"取消" style:UIAlertActionStyleDefault handler:^(UIAlertAction * _Nonnull action) {
        [weakSelf.navigationController popViewControllerAnimated:YES];
    }]];
    [self presentViewController:alertController animated:YES completion:nil];
    
}


//监听图片的改变
- (void)updateImage{
   // _shopImg = [ToolClass getDocumentImage:ImagePath];
    _dataDictionary[@"goods_image"] = [userDefaults objectForKey:@"HLBImageUrl"];
    [_defineShopTableView reloadRowsAtIndexPaths:@[[NSIndexPath indexPathForRow:2 inSection:0]] withRowAnimation:UITableViewRowAnimationNone];
}


//分类的选择视图的弹入弹出
- (void)selectCategory{
    [self.view endEditing:YES];
    if(_leftScrollView == nil){
        _leftScrollView = [[LeftScrollView alloc] initWithFrame:CGRectMake(-SCREEN_W/3, 0, SCREEN_W/3, _defineShopTableView.height)];
        _leftScrollView.delegate = self;
        NSMutableArray *labelArr = @[].mutableCopy;
        [_categoryArray enumerateObjectsUsingBlock:^(id  _Nonnull obj, NSUInteger idx, BOOL * _Nonnull stop) {
            CategoryListModel *model = obj;
            [labelArr addObject:model.category_name];
        }];
        _leftScrollView.allLabelData = labelArr;
        [self.view addSubview:_leftScrollView];
        [UIView animateWithDuration:0.2 animations:^{
            _leftScrollView.x = 0;
        } completion:^(BOOL finished) {
            
        }];
    }else{
        [UIView animateWithDuration:0.2 animations:^{
            _leftScrollView.x = -SCREEN_W/3;
        } completion:^(BOOL finished) {
            [_leftScrollView removeFromSuperview];
            _leftScrollView = nil;
            _leftScrollView.delegate = nil;
        }];

    }
    
}


#pragma  mark ========懒加载========

- (UITableView*)defineShopTableView{
    if(_defineShopTableView==nil){
        _defineShopTableView = [[UITableView alloc] initWithFrame:CGRectMake(0, 0, SCREEN_W, SCREEN_H-NavigationHeight-TableSafe-BottomViewHeight) style:UITableViewStyleGrouped];
        
        _defineShopTableView.delegate = self;
        _defineShopTableView.dataSource = self;
        _defineShopTableView.estimatedSectionHeaderHeight = 0;
        _defineShopTableView.estimatedRowHeight = 0;
        _defineShopTableView.estimatedSectionFooterHeight = 0;
        [_defineShopTableView registerClass:[UITableViewCell class] forCellReuseIdentifier:@"editFoodCell"];
    }
    return _defineShopTableView;
}

//添加删除 新增并保持 的视图
- (void)addBottomView{
    __weak typeof (self)weakself = self;
    UIView *bottomView = [[UIView alloc] initWithFrame:CGRectMake(0, _defineShopTableView.bottom, SCREEN_W, BottomViewHeight)];
    bottomView.backgroundColor = kGrayColor;
    
    UIButton *delBtn = [UIButton buttonWithType:UIButtonTypeSystem];
    delBtn.frame = CGRectMake(0, 0.3, SCREEN_W/2, BottomViewHeight-0.3);
    [delBtn setTitleColor:kBlackColor forState:UIControlStateNormal];
    [delBtn setBackgroundColor:kWhiteColor];
    [delBtn setTitle:@"删除" forState:UIControlStateNormal];
    [bottomView addSubview:delBtn];
    [delBtn handleControlEvent:UIControlEventTouchUpInside withBlock:^(id sender) {
        [weakself.view endEditing:YES];
        [weakself titleAction];
    }];
    
    UIButton *saveBtn = [UIButton buttonWithType:UIButtonTypeSystem];
    saveBtn.frame = CGRectMake(SCREEN_W/2, 0.3, SCREEN_W/2, BottomViewHeight-0.3);
    [saveBtn setTitle:@"保存并返回" forState:UIControlStateNormal];
    [saveBtn setTitleColor:kWhiteColor forState:UIControlStateNormal];
    [saveBtn setBackgroundColor:MianRedColor];
    [bottomView addSubview:saveBtn];
    [saveBtn handleControlEvent:UIControlEventTouchUpInside withBlock:^(id sender) {
        [weakself.view endEditing:YES];
        [weakself saveAndBack:_dataDictionary];
    }];

    [self.view addSubview:bottomView];
}

//库存无限的操作
- (void)updateState:(UISwitch*)sender{
    // isInventory = !isInventory;
    _dataDictionary[@"no_limit"] = [_dataDictionary[@"no_limit"] isEqualToString:@"1"]?@"0":@"1";
    [_defineShopTableView reloadSections:[NSIndexSet indexSetWithIndex:1] withRowAnimation:UITableViewRowAnimationNone];
}

//添加属性编辑的视图
#pragma  mark ========网络请求========
- (void)getGoodsInfo:(NSString *)shopID{
    
    __weak typeof (self)weakself = self;
    [[PPHttpRequsetData shareInstance] requestStyle:Request_POST URL:@"/ShopApi/Goods/getGoodsInfo" parameter:@{@"goods_id":shopID} successBlock:^(PPHttpRequest *request, id responseObj) {
        _dataDictionary =((NSDictionary *)responseObj).mutableCopy;
        _recordData = ((NSDictionary *)responseObj).mutableCopy;//记录初始数据
        _selectPropertyData = _dataDictionary[@"goods_sku"];
        [_defineShopTableView reloadData];
    } failBlock:^(PPHttpRequest *request, NSString *errMsg) {
        [AlertUtils showToastWithMessage:errMsg inView:self.view hideAfterDelay:2.0 beIndeter:NO];
    }];
}

- (void)titleAction{
    __weak typeof (self)weakself = self;
    UIAlertController *alertController = [UIAlertController alertControllerWithTitle:@"温馨提示" message:@"是否删除该商品" preferredStyle:UIAlertControllerStyleAlert];
    [alertController addAction:[UIAlertAction actionWithTitle:@"删除" style:UIAlertActionStyleDefault handler:^(UIAlertAction * _Nonnull action) {
        [weakself delGoods:_goodsID];
    }]];
    [alertController addAction:[UIAlertAction actionWithTitle:@"取消" style:UIAlertActionStyleDefault handler:^(UIAlertAction * _Nonnull action) {
        
    }]];
    [self presentViewController:alertController animated:YES completion:nil];
    
}


//删除商品
- (void)delGoods:(NSString *)shopID{
    __weak typeof (self)weakself = self;
    [[PPHttpRequsetData shareInstance] requestStyle:Request_POST URL:@"/ShopApi/Goods/goodsDel" isactive:NO parameter:@{@"goods_ids":shopID} successBlock:^(PPHttpRequest *request, NSArray* responseObj) {
        
        [AlertUtils showToastWithMessage:@"删除成功" inView:nil hideAfterDelay:2.0 beIndeter:NO];
        [weakself.navigationController popViewControllerAnimated:YES];
        
    } failBlock:^(PPHttpRequest *request, NSString *errMsg) {
        
        [AlertUtils showToastWithMessage:errMsg inView:self.view hideAfterDelay:2.0 beIndeter:NO];
        
    }];
}

//保持并返回
- (void)saveAndBack:(NSDictionary *)dic{
    NSMutableDictionary *newdic = dic.mutableCopy;
    NSArray *skuArray  = dic[@"goods_sku"];
    NSData *jsonData = [NSJSONSerialization dataWithJSONObject:skuArray options:NSJSONWritingPrettyPrinted error:nil];
    NSString *jsonStr = [[NSString alloc] initWithData:jsonData encoding:NSUTF8StringEncoding];
    newdic[@"goods_sku"] = jsonStr;
    __weak typeof (self)weakself = self;
    [[PPHttpRequsetData shareInstance] requestStyle:Request_POST URL:@"/ShopApi/Goods/goodsSave" isactive:NO parameter:newdic successBlock:^(PPHttpRequest *request, NSArray* responseObj) {
        
        [weakself.navigationController popViewControllerAnimated:YES];
        
    } failBlock:^(PPHttpRequest *request, NSString *errMsg) {
        
        [AlertUtils showToastWithMessage:errMsg inView:self.view hideAfterDelay:2.0 beIndeter:NO];
        
    }];
    
}

#pragma  mark ========UITabelView 协议方法========
- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView{
    return 3 + _selectPropertyData.count;
}

- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section{
    if(section==0){
        return 3;
    }else if(section == 1){
        if([_dataDictionary[@"no_limit"] isEqualToString:@"0"]) return 3;
        return 2;
    }else if(section==2){
        return 0;
    }else{
        NSDictionary *dic = _selectPropertyData[section-3];
        NSArray *dataArr = dic[@"attr_value_arr"];
        return dataArr.count;
    }
    return 0;
}

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath{
    UITableViewCell *cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:@"editFoodCell"];
    
    if(indexPath.section == 0){
        UILabel *title = [[UILabel alloc] init];
        title.font = font16;
        [cell.contentView addSubview:title];
        title.sd_layout.leftSpaceToView(cell.contentView, GETWITH(60)).centerYEqualToView(cell.contentView).widthIs(GETWITH(180)).heightIs(16);
        title.text = _titleArray[3*indexPath.section+indexPath.row];
        [self oneSectionStyle:cell rowIndexPath:indexPath titleLab:title];
    }else if (indexPath.section == 1){
        UILabel *title = [[UILabel alloc] init];
        title.font = font16;
        [cell.contentView addSubview:title];
        title.sd_layout.leftSpaceToView(cell.contentView, GETWITH(60)).centerYEqualToView(cell.contentView).widthIs(GETWITH(180)).heightIs(16);
        title.text = _titleArray[3*indexPath.section+indexPath.row];

        [self twoSectionStyle:cell rowIndexPath:indexPath titleLab:title];
    }
    if(indexPath.section>2){
        NSDictionary *dic = _selectPropertyData[indexPath.section-3];
        NSArray *dataArr = dic[@"attr_value_arr"];
        NSDictionary *dicdata = dataArr[indexPath.row];
    
        UILabel *guigeLab = [[UILabel alloc] init];
        guigeLab.font = font14;
        guigeLab.text = dicdata[@"attr_value"];
        [cell.contentView addSubview:guigeLab];
        guigeLab.sd_layout.leftSpaceToView(cell.contentView, GETWITH(100)).widthIs(GETWITH(140)).heightIs(30).centerYEqualToView(cell.contentView);
        
        UILabel *priceLab = [[UILabel alloc] init];
        priceLab.font = font14;
        priceLab.text = [NSString stringWithFormat:@"¥%@",dicdata[@"goods_price"]];
        [cell.contentView addSubview:priceLab];
        priceLab.sd_layout.leftSpaceToView(guigeLab, GETWITH(60)).widthIs(GETWITH(160)).heightIs(30).centerYEqualToView(cell.contentView);
        if([dic[@"is_main"] isEqualToString:@"0"]){
            priceLab.hidden = YES;
        }else{
            priceLab.hidden = NO;
        }
        

    }
    cell.selectionStyle = UITableViewCellSelectionStyleNone;
    return cell;
}



- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath{
    if(indexPath.section==0 && indexPath.row==2) return 56;
    return 45;
}

- (UIView *)tableView:(UITableView *)tableView viewForHeaderInSection:(NSInteger)section{
    UIView *view = [[UIView alloc] initWithFrame:CGRectMake(0, 0, SCREEN_W,0.1)];
    if(section==0 || section ==1){
         return [[UIView alloc] initWithFrame:CGRectMake(0, 0, SCREEN_W, 0.1)];
    }else if(section==2){
        UILabel *titleLab = [[UILabel alloc] initWithFrame:CGRectMake(GETWITH(30),10, GETWITH(200), 20)];
        titleLab.text = @"商品属性";
        titleLab.font = font17;
        [view addSubview:titleLab];
        
        view.backgroundColor = kWhiteColor;
        view.height = 40;
        UIButton *editBtn = [[UIButton alloc] init];
        editBtn.titleLabel.font = font14;
        [editBtn setTitleColor:UIColorFromRGB(0xff9000) forState:UIControlStateNormal];
        [editBtn setTitle:@"编辑属性" forState:UIControlStateNormal];
        [view addSubview:editBtn];
        editBtn.sd_layout.rightSpaceToView(view, GETWITH(30)).topSpaceToView(view, 10).widthIs(GETWITH(120)).heightIs(20);
        __weak typeof (self)weakself = self;
        [editBtn handleControlEvent:UIControlEventTouchUpInside withBlock:^(id sender) {
            EditAttributeVC *vc = [EditAttributeVC new];
            [weakself.view endEditing:YES];
            vc.goodsID = _goodsID;
            NSData *data = [userDefaults objectForKey:HLBPropertyListArray];
            NSMutableArray *teA = [NSKeyedUnarchiver unarchiveObjectWithData:data];
            vc.goodsAttr = teA;
            vc.goodsSKU = _dataDictionary[@"goods_sku"];
            vc.goods_Price = _dataDictionary[@"goods_price"];
            vc.completeBlock = ^(NSArray *array) {
                _selectPropertyData = array;
                _dataDictionary[@"goods_sku"] = array;
                [_defineShopTableView reloadData];
            };
            [weakself.navigationController pushViewController:vc animated:YES];
        }];
        return view;
    }else{
        NSDictionary *dic = _selectPropertyData[section-3];
        view.height = 30;
        view.backgroundColor = ControllerColor;
        UILabel *addFoodClass = [[UILabel alloc] initWithFrame:CGRectMake(GETWITH(60),0, GETWITH(200), GETHEIGHT(40))];
        addFoodClass.centerY = view.centerY;
        addFoodClass.font = font15;
        addFoodClass.text = dic[@"attr_name"];
        
        [view addSubview:addFoodClass];
        return view;
    }
    return [[UIView alloc] initWithFrame:CGRectMake(0, 0, SCREEN_W, 0.1)];
}

- (CGFloat)tableView:(UITableView *)tableView heightForHeaderInSection:(NSInteger)section{
    if (section==0||section == 1) return 0.1;
    else if (section == 2) return 40;
    else return 30;
    return 0.1;
}

- (UIView *)tableView:(UITableView *)tableView viewForFooterInSection:(NSInteger)section{
    NSInteger height = 0.1;
    if(section==1) height = 20;
    if(section==0) height = 10;
    UIView *view = [[UIView alloc] initWithFrame:CGRectMake(0, 0, SCREEN_W, height)];
    
    return view;
}

- (CGFloat)tableView:(UITableView *)tableView heightForFooterInSection:(NSInteger)section{
    if(section == 0) return 10;
    if(section==1) return 20;
    return 0.1;
}


- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath{
    if(indexPath.section == 0 && indexPath.row == 1){
        [self selectCategory];
    }
}

#pragma  mark ========输入框的代理========
- (void)textFieldDidEndEditing:(UITextField *)textField{
    switch (textField.tag) {
        case 0:
            _dataDictionary[@"goods_name"] = textField.text;
            break;
        case 1:
            _dataDictionary[@"goods_price"] = textField.text;
            break;
        case 3:
            _dataDictionary[@"goods_number"] = textField.text;
            break;
        default:
            break;
    }
}

- (BOOL)textFieldShouldBeginEditing:(UITextField *)textField {
    if (textField.tag == 100) {
        return NO;
    }
    return YES;
}

- (BOOL)textFieldShouldReturn:(UITextField *)textField{
    [textField resignFirstResponder];
    return YES;
}
-(void)textFieldDidBeginEditing:(UITextField *)textField{
    if(_leftScrollView){
        [UIView animateWithDuration:0.2 animations:^{
            _leftScrollView.x = -SCREEN_W/3;
        } completion:^(BOOL finished) {
            [_leftScrollView removeFromSuperview];
            _leftScrollView = nil;
            _leftScrollView.delegate = nil;
        }];
    }
}

#pragma  mark ========leftScrollView========
- (void)leftScrollSelectIndex:(NSIndexPath *)index{
    CategoryListModel *mode = _categoryArray[index.row];
    _dataDictionary[@"agent_category_id"] = mode.categoryID;
    [UIView animateWithDuration:0.2 animations:^{
        _leftScrollView.x = -SCREEN_W/3;
    } completion:^(BOOL finished) {
        [_leftScrollView removeFromSuperview];
        _leftScrollView = nil;
        _leftScrollView.delegate = nil;
        [_defineShopTableView reloadRowsAtIndexPaths:@[[NSIndexPath indexPathForRow:1 inSection:0]] withRowAnimation:UITableViewRowAnimationNone];
    }];
}

#pragma  mark ========选择相片========
- (void)chooseImage{
    PreviewImageVC *vc = [PreviewImageVC new];
    vc.imagePath = _dataDictionary[@"goods_image"];
    [self.navigationController pushViewController:vc animated:YES];
    
}

#pragma  mark ========单元格样式========
- (void)oneSectionStyle:(UITableViewCell *)cell rowIndexPath:(NSIndexPath *)indexPath titleLab:(UILabel *)title{
    UITextField *rightTextField = [[UITextField alloc] init];
    rightTextField.textAlignment = NSTextAlignmentRight;
    rightTextField.returnKeyType = UIReturnKeyDone;
    rightTextField.tag = indexPath.row + indexPath.section;
    rightTextField.delegate = self;
    rightTextField.font = font15;
    [cell.contentView addSubview:rightTextField];
    rightTextField.sd_layout.leftSpaceToView(title, GETWITH(30)).rightSpaceToView(cell.contentView, GETWITH(30)).heightIs(16).centerYEqualToView(title);
    if(indexPath.row == 0){
        rightTextField.placeholder = @"商品名称";
        rightTextField.text = _dataDictionary[@"goods_name"];
    }else if(indexPath.row == 1){
        
        //rightTextField.enabled = NO;
        rightTextField.placeholder = @"请选择商品分类";
        rightTextField.tag = 100;
        for (CategoryListModel *mode in _categoryArray) {
            if(mode.categoryID == _dataDictionary[@"agent_category_id"])
                rightTextField.text = mode.category_name;
        }
        UITapGestureRecognizer *tap = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(selectCategory)];
        rightTextField.userInteractionEnabled = YES;
        [rightTextField addGestureRecognizer:tap];
        
    }else{
        [rightTextField removeFromSuperview];
        title.sd_layout.leftSpaceToView(cell.contentView, GETWITH(60)).topSpaceToView(cell.contentView, 8).widthIs(GETWITH(180)).heightIs(16);
        
        UILabel *remind = [[UILabel alloc] init];
        remind.textColor = UIColorFromRGB(0xe6e6e6);
        remind.text = @"图片需大于100x100像素";
        remind.font = font11;
        [cell.contentView addSubview:remind];
        remind.sd_layout.leftEqualToView(title).topSpaceToView(title, 10).bottomSpaceToView(cell.contentView, 5).widthIs(150);
        
        UIImageView *addshopImg = [[UIImageView alloc] init];
        if(_shopImg){
            addshopImg.image = _shopImg;
            
        }else{
            if(_dataDictionary[@"goods_image"]){
                [addshopImg sd_setImageWithURL:[NSURL URLWithString:_dataDictionary[@"goods_image"]] placeholderImage:[UIImage imageNamed:@"edit_note2_default"]];
            }else{
                addshopImg.image = [UIImage imageNamed:@"edit_bg1_default_nor"];
                
            }
        }
        UITapGestureRecognizer *tap = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(chooseImage)];
        addshopImg.userInteractionEnabled = YES;
        [addshopImg addGestureRecognizer:tap];
        
        [cell.contentView addSubview:addshopImg];
        addshopImg.sd_layout.rightSpaceToView(cell.contentView, GETWITH(30)).centerYEqualToView(cell.contentView).widthIs(GETWITH(80)).heightEqualToWidth();
    }
}


- (void)twoSectionStyle:(UITableViewCell *)cell rowIndexPath:(NSIndexPath *)indexPath titleLab:(UILabel *)title{
    UITextField *rightTextField = [[UITextField alloc] init];
    rightTextField.textAlignment = NSTextAlignmentRight;
    rightTextField.returnKeyType = UIReturnKeyDone;
    rightTextField.delegate = self;
    rightTextField.font = font15;
    rightTextField.tag = indexPath.row + indexPath.section;
    [cell.contentView addSubview:rightTextField];
    rightTextField.sd_layout.leftSpaceToView(title, GETWITH(30)).rightSpaceToView(cell.contentView, GETWITH(30)).heightIs(16).centerYEqualToView(title);
    if(indexPath.row == 0){
        rightTextField.placeholder = @"请填写价格";
        rightTextField.text = _dataDictionary[@"goods_price"];
        
    }else if(indexPath.row == 1){
        [rightTextField removeFromSuperview];
        UISwitch *witch = [[UISwitch alloc] init];
        witch.onTintColor = MianRedColor;
        if([_dataDictionary[@"no_limit"] isEqualToString:@"1"]){//库存无限
            witch.on = YES;
        }else{
            witch.on = NO;
        }
        [witch addTarget:self action:@selector(updateState:) forControlEvents:UIControlEventTouchUpInside];
        [cell.contentView addSubview:witch];
        witch.sd_layout.rightSpaceToView(cell.contentView, GETWITH(30)).widthIs(GETWITH(100))
        .heightIs(30).centerYEqualToView(cell.contentView);
    }else{
        rightTextField.placeholder = @"请输入数量";
        rightTextField.text = _dataDictionary[@"goods_number"];
    }

}
@end
